package zhoujunhao.rbac.view;

import java.util.Scanner;

public class Mainview {

    public static final String MENU = """
            ------------
            RBAC系统
            0.退出系统
            1. 部门管理
            2. 角色管理
            3. 用户管理
            ------------
            请输入选项：
            """;

    public static Scanner input;
    private static Mainview singleton;

    static {
        input = new Scanner(System.in);
    }

    private final Deptview deptview;
    private final Roleview roleview;
    private final Userview userview;

    private Mainview() {
        deptview = Deptview.getInstance();
        roleview = Roleview.getInstance();
        userview = Userview.getInstance();
    }

    public static Mainview getInstance() {
        if (singleton == null) {
            singleton = new Mainview();
        }
        return singleton;
    }

    /**
     * 显示界面
     */
    public void show() {
        String menuChoice;
        do {
            System.out.println(MENU);
            menuChoice = input.nextLine();
            switch (menuChoice) {
                case "0":
                    System.out.println("成功退出系统，欢迎再次使用");
                    break;
                case "1":
                    deptview.show();
                    break;
                case "2":
                    roleview.show();
                    break;
                case "3":
                    userview.show();
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
            }
        } while (!"0".equals(menuChoice));
        input.close();

    }

}
